<html>

<head>

<title>Simple API Client</title>

<script src="http://code.jquery.com/jquery-latest.min.js"
	type="text/javascript"></script>

<script language="javascript" type="text/javascript">

$(function() {

	  $('#getAllBtn').click(function(){
			$.ajax({
			    type: "GET", 
			    url: "index.php/address/",
			    success: function (data, text) {
			    	 $('#output').html(JSON.stringify(data));
			    },
			    error: function (request, status, error) {
			        $('#output').html(status + ' : ' + error + ' - ' + request.responseText);
			    }
			}); 
			
	  });

	  $('#getBtn').click(function(){
			$.ajax({
			    type: "GET", 
			    url: "index.php/address/id/1",
			    success: function (data, text) {
			    	 $('#output').html(JSON.stringify(data));
			    },
			    error: function (request, status, error) {
			        $('#output').html(status + ' : ' + error + ' - ' + request.responseText);
			    }
			}); 
			
	  });

	  $('#updateBtn').click(function(){
		    var params = {};
		    params['name'] = "Marcin"
		    params['phone'] = "502145785"
		    params['street'] = "Gipsy Lane"			    
			$.ajax({
			    type: "PUT", 
			    url: "index.php/address/id/1",
			    data: params,
			    success: function (data, text) {
			    	 $('#output').html(JSON.stringify(data));
			    },
			    error: function (request, status, error) {
			        $('#output').html(status + ' : ' + error + ' - ' + request.responseText);
			    }
			}); 
			
	  });

	  $('#createBtn').click(function(){
		    var params = {};
		    params['name'] = "Milena"
		    params['phone'] = "803845717"
		    params['street'] = "Muggenhofer Str. 50"
			    
			$.ajax({
			    type: "POST", 
			    url: "index.php/address/",
			    data: params,
			    success: function (data, text) {
			    	 $('#output').html(JSON.stringify(data));
			    },
			    error: function (request, status, error) {
			        $('#output').html(status + ' : ' + error + ' - ' + request.responseText);
			    }
			}); 
			
	  });

	  $('#deleteBtn').click(function(){
		    $.ajax({
			    type: "DELETE", 
			    url: "index.php/address/id/4",
			    success: function (data, text) {
			    	 $('#output').html(JSON.stringify(data));
			    },
			    error: function (request, status, error) {
			        $('#output').html(status + ' : ' + error + ' ' + request.responseText);
			    }
			});	
	  });
	  
	  
});
	


</script>

</head>

<body>

	<button id="getAllBtn">Get All</button>
	<button id="getBtn" title="Get the first record">Get Record #1</button>
	<button id="updateBtn">Update Record #1</button>
	<button id="createBtn">Create Record</button>
	<button id="deleteBtn" title="Get record #4">Delete Record #4</button>

	<div id="output"
		style="border: 1px solid #cccccc; padding: 20px; width: 80%; height: 300px;"></div>

</body>

</html>